package 反射1;

import java.lang.reflect.Field;

public class TestCar {
    public static void main(String[] args) throws Exception{
     String classAllPath="反射.Car";
     //1.获取car类对象堆中Class对象
        Class<?> aClass = Class.forName(classAllPath);
        System.out.println("aclsss="+aClass);
        System.out.println("aClass.getClass()="+aClass.getClass());
        System.out.println(aClass.getPackage());
        System.out.println(aClass.getName());
        Car car= (Car) aClass.newInstance();
        System.out.println("Car="+car);
        Field brand = aClass.getField("brand");
        System.out.println(brand.get(car));
        Field[] brands = aClass.getFields();
        for (Field f:brands){
            System.out.println(f.getName());
            System.out.println("------------获取反射类对象----------");
            Car car1 = new Car();//硬编码
            Class<? extends Car> aClass1 = car1.getClass();
            System.out.println(aClass1);

            //3.通过class属性获取
            System.out.println(Car.class);

/////////////4.通过类加载器
            ClassLoader classLoader = car1.getClass().getClassLoader();
            Class<?> aClass2 = classLoader.loadClass(classAllPath);
            System.out.println(aClass2);
            System.out.println(aClass.hashCode());

            System.out.println(aClass1.hashCode());

            System.out.println(aClass2.hashCode());

            Class<Integer> integerClass = int.class;
            System.out.println(char.class);
            System.out.println(boolean.class);


        }

    }
}
